﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using ContactWP.Resources;
using Newtonsoft.Json;

namespace ContactWP
{
    public class PersonObj
    {
        public string PersonName { get; set; }
        public string PersonCompany { get; set; }
        public string PersonDesignation { get; set; }
        public string PersonEmail { get; set; }
        public string PersonCell { get; set; }
        public int Win8 { get; set; }
        public int WP { get; set; }
    }
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();

            // Sample code to localize the ApplicationBar
            //BuildLocalizedApplicationBar();
        }

        private void ApplicationBarIconButton_Click(object sender, EventArgs e)
        {
            ServiceReference1.Service1Client client = new ServiceReference1.Service1Client();

            PersonObj person = new PersonObj();

            person.PersonCell = PersonCell.Text;
            person.PersonCompany = PersonCompany.Text;
            person.PersonDesignation = PersonDesignation.Text;
            person.PersonEmail = PersonEmail.Text;
            person.PersonName = PersonName.Text;

            person.Win8 = Convert.ToInt32(checkWin8.IsChecked.Value);
            person.WP = Convert.ToInt32(checkWP.IsChecked.Value);

            client.SaveDataAsync(JsonConvert.SerializeObject(person));
            client.SaveDataCompleted += client_SaveDataCompleted;
        }

        void client_SaveDataCompleted(object sender, ServiceReference1.SaveDataCompletedEventArgs e)
        {
            MessageBox.Show(e.Result);
        }

        // Sample code for building a localized ApplicationBar
        //private void BuildLocalizedApplicationBar()
        //{
        //    // Set the page's ApplicationBar to a new instance of ApplicationBar.
        //    ApplicationBar = new ApplicationBar();

        //    // Create a new button and set the text value to the localized string from AppResources.
        //    ApplicationBarIconButton appBarButton = new ApplicationBarIconButton(new Uri("/Assets/AppBar/appbar.add.rest.png", UriKind.Relative));
        //    appBarButton.Text = AppResources.AppBarButtonText;
        //    ApplicationBar.Buttons.Add(appBarButton);

        //    // Create a new menu item with the localized string from AppResources.
        //    ApplicationBarMenuItem appBarMenuItem = new ApplicationBarMenuItem(AppResources.AppBarMenuItemText);
        //    ApplicationBar.MenuItems.Add(appBarMenuItem);
        //}
    }
}